package com.atguigu.mvc.handler;

import com.atguigu.mvc.entity.Employee;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class TargetHandler {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @RequestMapping("/save/emp")
    public String saveEmp(Employee employee,

              // 在实体类参数和 BindingResult 之间不能有任何其他参数
              // 封装数据绑定结果的对象
              BindingResult bindingResult) {

        // 判断数据绑定过程中是否发生了错误
        if (bindingResult.hasErrors()) {

            // 前往指定页面
            return "error";
        }

        logger.debug(employee.getBirthday().toString());
        logger.debug(employee.getAddress().toString());

        return "target";
    }

}
